package com.gidgabs.modules.api.controller;

import java.util.List;
import java.util.Map;

import com.gidgabs.common.utils.PageUtils;
import com.gidgabs.common.utils.Query;
import com.gidgabs.common.utils.R;
import com.gidgabs.modules.api.service.TbUserFriendsService;
import com.gidgabs.modules.entity.TbUserFriendsEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户关系表-朋友中间表
 * 
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-07-02 10:07:40
 */
@RestController
@RequestMapping("/api/userfriends")
public class TbUserFriendsController {
	@Autowired
	private TbUserFriendsService userFriendsService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("userfriends:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TbUserFriendsEntity> userFriendsList = userFriendsService.queryList(query);
		int total = userFriendsService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(userFriendsList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("userfriends:info")
	public R info(@PathVariable("id") Integer id){
		TbUserFriendsEntity userFriends = userFriendsService.queryObject(id);
		
		return R.ok().put("userFriends", userFriends);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("userfriends:save")
	public R save(@RequestBody TbUserFriendsEntity userFriends){
		userFriendsService.save(userFriends);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("userfriends:update")
	public R update(@RequestBody TbUserFriendsEntity userFriends){
		userFriendsService.update(userFriends);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("userfriends:delete")
	public R delete(@RequestBody Integer[] ids){
		userFriendsService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
